package sisi;

import java.util.Map;

import org.zkoss.zk.ui.event.CreateEvent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zk.ui.util.ConventionWires;
import org.zkoss.zul.Intbox;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

@SuppressWarnings({ "unchecked", "serial" })
public class ConfigurationWindow extends Window implements 
				org.zkoss.zk.ui.ext.AfterCompose {
//window
private Window windowEditConfiguration;
protected Map<String, Object> args;
private Configuration modConfiguration;
// edit
private Intbox id;
private Textbox agentnomination, agentinformation;


	public void afterCompose() {

		// wire variables
		ConventionWires.wireVariables(this, this);

		// auto forward
		ConventionWires.addForwards(this, this);

	}


// EDIT: NEW/MODIFY
	public void onCreate$windowEditConfiguration(Event event) {

		CreateEvent ce = (CreateEvent) ((ForwardEvent) event).getOrigin();
		args = (Map<String, Object>) ce.getArg();

		modConfiguration = new ConfigurationController().getxId(1);
		windowEditConfiguration.setTitle("Edit Configuration");
		id.setValue(modConfiguration.getId());
		agentnomination.setValue(modConfiguration.getAgentnomination());
		agentinformation.setValue(modConfiguration.getAgentinformation());
		agentnomination.setFocus(true);

	}

	public void onClick$btnAnnulla(Event event){
		windowEditConfiguration.detach();
	}

	public void onClick$btnConferma(Event event){
		String testoMsg = "";

		modConfiguration.setId(id.getValue());
		modConfiguration.setAgentnomination(agentnomination.getValue());
		modConfiguration.setAgentinformation(agentinformation.getValue());

		new ConfigurationController().update(modConfiguration);
		testoMsg = "Aggiornando Configuration: "+ General.trimNull( modConfiguration.getAgentnomination() );

		General.showNotify( testoMsg, windowEditConfiguration);

		windowEditConfiguration.detach();

	}

}
